A conventional reciprocating compressor utilizes a crank-shaft mechanism to convert the rotational motion of the motor into the oscillating motion to drive a piston of the compressor and a frequency inverter is used to regulate the performance of the piston according to the load variation. However, the conventional compressor can be replaced by a compressor utilizing a linear motor to drive a piston of the compressor. Although this kind of compressor has lower noise and less vibration and wear than the conventional reciprocating compressor, the stroke of the piston is easily influenced by the exhaust pressure of the compressor without the crank and shaft to fix the movement of the piston. It brings about a low performance of this kind of the compressor. Therefore, the present invention provides a controller to regulate the piston stroke and to control the frequency of the movement of the piston under various operating conditions.